package com.willie.boot.rabbit;

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * 消息提供方
 *
 * @author willie
 * @since 2018-10-29 11:23:04
 */
public class RabbitMQProvider {
    // 对列名称
    private static final String QUEUE_NAME = "hey";
    //主机地址
    private static final String HOST = "192.168.10.50";

    public static void main(String[] args) {
        ConnectionFactory factory = new CachingConnectionFactory(HOST);
        AmqpAdmin admin = new RabbitAdmin(factory);
        admin.declareQueue(new Queue(QUEUE_NAME));
        AmqpTemplate rabbitmqTemplate = new RabbitTemplate(factory);
        rabbitmqTemplate.convertAndSend(QUEUE_NAME, "hello rabbitmq");
    }
}
